package com.android.hq.ganktoutiao.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.android.hq.ganktoutiao.R;
import com.android.hq.ganktoutiao.data.GanNewsItem;
import com.android.hq.ganktoutiao.data.GankItem;
import com.android.hq.ganktoutiao.data.NewsItem;
import com.android.hq.ganktoutiao.data.NewsSildeItem;
import com.android.hq.ganktoutiao.data.bean.GanNewsResponse;
import com.android.hq.ganktoutiao.network.CallBack;
import com.android.hq.ganktoutiao.network.RequestManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/2.
 */
public class GankNewsFragment extends BaseFragment{

    @Override
    public void updateData() {
        RequestManager.getInstance().getdayNews(new CallBack<GanNewsResponse>() {
            @Override
            public void onSuccess(GanNewsResponse ganNewsResponse) {
                mRefreshLayout.setRefreshing(false);
                ArrayList<GankItem> list  = new ArrayList<GankItem>();
                GanNewsItem t = ganNewsResponse.t;
                NewsSildeItem sildeItem = new NewsSildeItem(t.slide);
                List<NewsItem> newsList = t.news;
                list.add(sildeItem);
                list.addAll(newsList);
                mAdapter.updateData(list);

                updateSuccess(list.isEmpty());
            }

            @Override
            public void onFail() {
                mRefreshLayout.setRefreshing(false);
                updateError();

            }
        });

    }

    @Override
    public void loadMore() {

    }

    @Override
    public boolean isEnablePullRefresh() {
        return true;
    }

    @Override
    public boolean isEnableLoadingMore() {
        return true;
    }

    @Override
    public boolean isEnableRefreshOnViewCreate() {
        return true;
    }


}
